package icdwkang;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

import B_DAO.Emp_DAO;
import B_DB.B_ProjectDB;

import javax.swing.DefaultComboBoxModel;

public class AddEmp extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField txt_Name;
	private JTextField txt_Birth;
	private JTextField txt_Ssn1;
	private JTextField txt_Ssn2;
	private JTextField txt_Phone;
	private JTextField txt_Post1;
	private JTextField txt_Post2;
	private JTextField txt_Addr1;
	private JTextField txt_Addr2;
	private JTextField txt_Saddr;
	private JTextField txt_Hiredate;
	private JTextField txt_Sal;
	private Emp_DAO edao = new Emp_DAO();
	private EmpVO evo = new EmpVO();
	private JTextField txt_Deptno;
	private JTextField txt_Job;
	private B_ProjectDB bdb; // db연결을 위해 B_ProjectDB 클래스 변수 선언

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			AddEmp dialog = new AddEmp();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public AddEmp() {
		setTitle(" :: 직 원 정 보 등 록 ::");
		setBounds(100, 100, 536, 523);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.NORTH);
		JLabel photo_lbl = new JLabel("");
		photo_lbl.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
		JButton photo_Btn = new JButton(" 사진등록 ");
		JLabel lbl_Name = new JLabel(" 이름 ");
		txt_Name = new JTextField();
		txt_Name.setColumns(10);

		JLabel lbl_Birth = new JLabel(" 생년월일 ");

		txt_Birth = new JTextField();
		txt_Birth.setColumns(10);

		JLabel lbl_Ssn = new JLabel(" 주민등록번호 ");

		txt_Ssn1 = new JTextField();
		txt_Ssn1.setColumns(10);

		txt_Ssn2 = new JTextField();
		txt_Ssn2.setColumns(10);

		JLabel label_2 = new JLabel("-");

		JLabel lbl_Phone = new JLabel(" 전화번호 ");

		txt_Phone = new JTextField();
		txt_Phone.setColumns(10);

		JLabel lbl_Addr = new JLabel(" 주소 ");

		txt_Post1 = new JTextField();
		txt_Post1.setColumns(10);

		txt_Post2 = new JTextField();
		txt_Post2.setColumns(10);

		JLabel label_5 = new JLabel("-");

		JButton Zip_btn = new JButton(" 우편번호 검색 ");
		Zip_btn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ZipcodeSub z = new ZipcodeSub(txt_Post1, txt_Post2, txt_Addr1,
						txt_Addr2);
				z.setVisible(true);
			}
		});

		txt_Addr1 = new JTextField();
		txt_Addr1.setColumns(10);

		txt_Addr2 = new JTextField();
		txt_Addr2.setColumns(10);

		JLabel lbl_Sname = new JLabel(" 보호소명 ");

		final JComboBox cb_Sname = new JComboBox();
		cb_Sname.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				txt_Saddr.setText((String) cb_Sname.getSelectedItem());
			}
		});
		cb_Sname.setModel(new DefaultComboBoxModel(new String[] { " ",
				"한국동물구조관리협회", "카라(사)동물보호시민단체", "동물학대방지연합", "부산동물학대방지연합",
				"대전동물보호센터", "동물보호센터", "한국동물보호협회", "동물자유연대", "부산유기동물보호협회",
				"하늘아이", "동물사랑실천협회", "캐비클럽", "동물보호관리시스템", "(사)한국야생동물보호협회" }));

		txt_Saddr = new JTextField();
		txt_Saddr.setColumns(10);

		JLabel lbl_Dname = new JLabel(" 부서명 ");

		final JComboBox cb_Dname = new JComboBox();
		cb_Dname.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				txt_Deptno.setText((String) cb_Dname.getSelectedItem());
			}
		});
		cb_Dname.setModel(new DefaultComboBoxModel(new String[] { "", "동물구조",
				"시설관리", "자재관리", "동물관리", "사무" }));

		JLabel lbl_Deptno = new JLabel(" 부서번호");
		txt_Deptno = new JTextField();
		txt_Deptno.setColumns(10);

		JLabel lbl_Job = new JLabel(" 담당업무 ");

		JLabel lbl_Hiredate = new JLabel(" 입사일 ");

		txt_Hiredate = new JTextField();
		txt_Hiredate.setColumns(10);

		JLabel lbl_Mgr = new JLabel(" 직위 ");

		JComboBox cb_Mgr = new JComboBox();

		JLabel lbl_Sal = new JLabel(" 급여 ");

		txt_Sal = new JTextField();
		txt_Sal.setColumns(10);

		final JButton ok_Btn = new JButton(" 등록 ");
		ok_Btn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int choice = JOptionPane.showConfirmDialog(ok_Btn, "등록하시겠습니까?",
						"직원정보등록", JOptionPane.YES_NO_OPTION);
				if (choice == JOptionPane.YES_OPTION) {
					evo = new EmpVO(txt_Name.getText(), txt_Birth.getText(),
							txt_Ssn1.getText() + txt_Ssn2.getText(), txt_Phone
									.getText(), txt_Addr1.getText()
									+ txt_Addr2.getText(), txt_Saddr.getText(),
							txt_Deptno.getText(), txt_Hiredate.getText(),
							txt_Post1.getText(), txt_Sal.getText(), txt_Job
									.getText());	}
				else dispose();
					
			if(edao.insertEmp(evo)>0)
				JOptionPane.showMessageDialog(null, "등록완료");
			}
		});

		JButton cancle_Btn = new JButton(" 취소 ");
		cancle_Btn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});

		txt_Job = new JTextField();
		txt_Job.setColumns(10);
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel
				.setHorizontalGroup(gl_contentPanel
						.createParallelGroup(Alignment.TRAILING)
						.addGroup(
								gl_contentPanel
										.createSequentialGroup()
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.TRAILING)
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				ok_Btn)
																		.addGap(18)
																		.addComponent(
																				cancle_Btn,
																				GroupLayout.PREFERRED_SIZE,
																				76,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createParallelGroup(
																				Alignment.LEADING)
																		.addGroup(
																				gl_contentPanel
																						.createSequentialGroup()
																						.addGroup(
																								gl_contentPanel
																										.createParallelGroup(
																												Alignment.LEADING)
																										.addGroup(
																												gl_contentPanel
																														.createSequentialGroup()
																														.addGap(63)
																														.addComponent(
																																photo_Btn))
																										.addGroup(
																												gl_contentPanel
																														.createSequentialGroup()
																														.addGap(13)
																														.addGroup(
																																gl_contentPanel
																																		.createParallelGroup(
																																				Alignment.LEADING)
																																		.addGroup(
																																				gl_contentPanel
																																						.createSequentialGroup()
																																						.addComponent(
																																								lbl_Sname)
																																						.addPreferredGap(
																																								ComponentPlacement.RELATED)
																																						.addComponent(
																																								cb_Sname,
																																								0,
																																								139,
																																								Short.MAX_VALUE))
																																		.addComponent(
																																				photo_lbl,
																																				GroupLayout.PREFERRED_SIZE,
																																				184,
																																				GroupLayout.PREFERRED_SIZE)
																																		.addGroup(
																																				gl_contentPanel
																																						.createSequentialGroup()
																																						.addComponent(
																																								lbl_Dname)
																																						.addPreferredGap(
																																								ComponentPlacement.RELATED)
																																						.addComponent(
																																								cb_Dname,
																																								GroupLayout.PREFERRED_SIZE,
																																								81,
																																								GroupLayout.PREFERRED_SIZE)
																																						.addGap(18)
																																						.addComponent(
																																								lbl_Deptno)))))
																						.addPreferredGap(
																								ComponentPlacement.UNRELATED)
																						.addGroup(
																								gl_contentPanel
																										.createParallelGroup(
																												Alignment.TRAILING)
																										.addComponent(
																												txt_Addr2,
																												GroupLayout.DEFAULT_SIZE,
																												239,
																												Short.MAX_VALUE)
																										.addComponent(
																												txt_Addr1,
																												239,
																												239,
																												Short.MAX_VALUE)
																										.addGroup(
																												Alignment.LEADING,
																												gl_contentPanel
																														.createSequentialGroup()
																														.addComponent(
																																lbl_Phone,
																																GroupLayout.PREFERRED_SIZE,
																																84,
																																GroupLayout.PREFERRED_SIZE)
																														.addGap(18)
																														.addComponent(
																																txt_Phone,
																																GroupLayout.PREFERRED_SIZE,
																																137,
																																GroupLayout.PREFERRED_SIZE))
																										.addGroup(
																												Alignment.LEADING,
																												gl_contentPanel
																														.createSequentialGroup()
																														.addComponent(
																																lbl_Ssn,
																																GroupLayout.PREFERRED_SIZE,
																																84,
																																GroupLayout.PREFERRED_SIZE)
																														.addGap(18)
																														.addComponent(
																																txt_Ssn1,
																																GroupLayout.PREFERRED_SIZE,
																																57,
																																GroupLayout.PREFERRED_SIZE)
																														.addPreferredGap(
																																ComponentPlacement.RELATED)
																														.addComponent(
																																label_2)
																														.addPreferredGap(
																																ComponentPlacement.RELATED)
																														.addComponent(
																																txt_Ssn2,
																																0,
																																0,
																																Short.MAX_VALUE))
																										.addGroup(
																												Alignment.LEADING,
																												gl_contentPanel
																														.createSequentialGroup()
																														.addComponent(
																																lbl_Name,
																																GroupLayout.PREFERRED_SIZE,
																																84,
																																GroupLayout.PREFERRED_SIZE)
																														.addGap(18)
																														.addComponent(
																																txt_Name,
																																GroupLayout.PREFERRED_SIZE,
																																137,
																																GroupLayout.PREFERRED_SIZE))
																										.addGroup(
																												Alignment.LEADING,
																												gl_contentPanel
																														.createSequentialGroup()
																														.addComponent(
																																lbl_Birth,
																																GroupLayout.PREFERRED_SIZE,
																																84,
																																GroupLayout.PREFERRED_SIZE)
																														.addGap(18)
																														.addComponent(
																																txt_Birth,
																																GroupLayout.PREFERRED_SIZE,
																																137,
																																GroupLayout.PREFERRED_SIZE))
																										.addGroup(
																												Alignment.LEADING,
																												gl_contentPanel
																														.createSequentialGroup()
																														.addComponent(
																																lbl_Addr,
																																GroupLayout.PREFERRED_SIZE,
																																84,
																																GroupLayout.PREFERRED_SIZE)
																														.addGap(18)
																														.addGroup(
																																gl_contentPanel
																																		.createParallelGroup(
																																				Alignment.LEADING,
																																				false)
																																		.addComponent(
																																				Zip_btn,
																																				GroupLayout.DEFAULT_SIZE,
																																				GroupLayout.DEFAULT_SIZE,
																																				Short.MAX_VALUE)
																																		.addGroup(
																																				gl_contentPanel
																																						.createSequentialGroup()
																																						.addComponent(
																																								txt_Post1,
																																								GroupLayout.PREFERRED_SIZE,
																																								57,
																																								GroupLayout.PREFERRED_SIZE)
																																						.addGap(5)
																																						.addComponent(
																																								label_5,
																																								GroupLayout.PREFERRED_SIZE,
																																								6,
																																								GroupLayout.PREFERRED_SIZE)
																																						.addGap(5)
																																						.addComponent(
																																								txt_Post2,
																																								GroupLayout.PREFERRED_SIZE,
																																								64,
																																								GroupLayout.PREFERRED_SIZE))))
																										.addGroup(
																												Alignment.LEADING,
																												gl_contentPanel
																														.createSequentialGroup()
																														.addComponent(
																																txt_Deptno,
																																GroupLayout.PREFERRED_SIZE,
																																84,
																																GroupLayout.PREFERRED_SIZE)
																														.addGap(18)
																														.addComponent(
																																lbl_Job)
																														.addPreferredGap(
																																ComponentPlacement.UNRELATED)
																														.addComponent(
																																txt_Job,
																																GroupLayout.PREFERRED_SIZE,
																																78,
																																GroupLayout.PREFERRED_SIZE))
																										.addComponent(
																												txt_Saddr,
																												GroupLayout.DEFAULT_SIZE,
																												239,
																												Short.MAX_VALUE))
																						.addPreferredGap(
																								ComponentPlacement.RELATED))
																		.addGroup(
																				gl_contentPanel
																						.createSequentialGroup()
																						.addContainerGap()
																						.addComponent(
																								lbl_Hiredate)
																						.addGap(18)
																						.addComponent(
																								txt_Hiredate,
																								GroupLayout.PREFERRED_SIZE,
																								GroupLayout.DEFAULT_SIZE,
																								GroupLayout.PREFERRED_SIZE)
																						.addPreferredGap(
																								ComponentPlacement.UNRELATED)
																						.addComponent(
																								lbl_Mgr)
																						.addPreferredGap(
																								ComponentPlacement.RELATED)
																						.addComponent(
																								cb_Mgr,
																								GroupLayout.PREFERRED_SIZE,
																								59,
																								GroupLayout.PREFERRED_SIZE)
																						.addGap(24)
																						.addComponent(
																								lbl_Sal)
																						.addPreferredGap(
																								ComponentPlacement.UNRELATED)
																						.addComponent(
																								txt_Sal,
																								GroupLayout.DEFAULT_SIZE,
																								98,
																								Short.MAX_VALUE))))
										.addGap(110)));
		gl_contentPanel
				.setVerticalGroup(gl_contentPanel
						.createParallelGroup(Alignment.LEADING)
						.addGroup(
								gl_contentPanel
										.createSequentialGroup()
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				photo_lbl,
																				GroupLayout.DEFAULT_SIZE,
																				226,
																				Short.MAX_VALUE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(24)
																		.addGroup(
																				gl_contentPanel
																						.createParallelGroup(
																								Alignment.BASELINE)
																						.addComponent(
																								lbl_Name)
																						.addComponent(
																								txt_Name,
																								GroupLayout.PREFERRED_SIZE,
																								GroupLayout.DEFAULT_SIZE,
																								GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				ComponentPlacement.UNRELATED)
																		.addGroup(
																				gl_contentPanel
																						.createParallelGroup(
																								Alignment.LEADING)
																						.addGroup(
																								gl_contentPanel
																										.createSequentialGroup()
																										.addGap(3)
																										.addComponent(
																												lbl_Birth))
																						.addComponent(
																								txt_Birth,
																								GroupLayout.PREFERRED_SIZE,
																								GroupLayout.DEFAULT_SIZE,
																								GroupLayout.PREFERRED_SIZE))
																		.addGroup(
																				gl_contentPanel
																						.createParallelGroup(
																								Alignment.LEADING)
																						.addGroup(
																								gl_contentPanel
																										.createSequentialGroup()
																										.addGap(13)
																										.addComponent(
																												lbl_Ssn))
																						.addGroup(
																								gl_contentPanel
																										.createSequentialGroup()
																										.addPreferredGap(
																												ComponentPlacement.UNRELATED)
																										.addGroup(
																												gl_contentPanel
																														.createParallelGroup(
																																Alignment.BASELINE)
																														.addComponent(
																																txt_Ssn1,
																																GroupLayout.PREFERRED_SIZE,
																																GroupLayout.DEFAULT_SIZE,
																																GroupLayout.PREFERRED_SIZE)
																														.addComponent(
																																txt_Ssn2,
																																GroupLayout.PREFERRED_SIZE,
																																GroupLayout.DEFAULT_SIZE,
																																GroupLayout.PREFERRED_SIZE)
																														.addComponent(
																																label_2))))
																		.addPreferredGap(
																				ComponentPlacement.UNRELATED)
																		.addGroup(
																				gl_contentPanel
																						.createParallelGroup(
																								Alignment.LEADING)
																						.addGroup(
																								gl_contentPanel
																										.createSequentialGroup()
																										.addGap(3)
																										.addComponent(
																												lbl_Phone))
																						.addComponent(
																								txt_Phone,
																								GroupLayout.PREFERRED_SIZE,
																								GroupLayout.DEFAULT_SIZE,
																								GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				ComponentPlacement.RELATED,
																				13,
																				Short.MAX_VALUE)
																		.addGroup(
																				gl_contentPanel
																						.createParallelGroup(
																								Alignment.TRAILING,
																								false)
																						.addGroup(
																								gl_contentPanel
																										.createSequentialGroup()
																										.addGroup(
																												gl_contentPanel
																														.createParallelGroup(
																																Alignment.LEADING)
																														.addComponent(
																																txt_Post1,
																																GroupLayout.PREFERRED_SIZE,
																																GroupLayout.DEFAULT_SIZE,
																																GroupLayout.PREFERRED_SIZE)
																														.addGroup(
																																gl_contentPanel
																																		.createSequentialGroup()
																																		.addGap(3)
																																		.addComponent(
																																				label_5))
																														.addComponent(
																																txt_Post2,
																																GroupLayout.PREFERRED_SIZE,
																																GroupLayout.DEFAULT_SIZE,
																																GroupLayout.PREFERRED_SIZE))
																										.addPreferredGap(
																												ComponentPlacement.UNRELATED)
																										.addComponent(
																												Zip_btn)
																										.addPreferredGap(
																												ComponentPlacement.UNRELATED))
																						.addGroup(
																								gl_contentPanel
																										.createSequentialGroup()
																										.addComponent(
																												lbl_Addr)
																										.addGap(28)))
																		.addComponent(
																				txt_Addr1,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE)))
										.addPreferredGap(
												ComponentPlacement.UNRELATED)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.BASELINE)
														.addComponent(photo_Btn)
														.addComponent(
																txt_Addr2,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE))
										.addGap(18)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addComponent(lbl_Sname)
														.addGroup(
																gl_contentPanel
																		.createParallelGroup(
																				Alignment.BASELINE)
																		.addComponent(
																				cb_Sname,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE)
																		.addComponent(
																				txt_Saddr,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE)))
										.addGap(18)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.BASELINE)
														.addComponent(lbl_Dname)
														.addComponent(
																cb_Dname,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																lbl_Deptno)
														.addComponent(
																txt_Deptno,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(lbl_Job)
														.addComponent(
																txt_Job,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE))
										.addGap(18)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.BASELINE)
														.addComponent(
																lbl_Hiredate)
														.addComponent(
																txt_Hiredate,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cb_Mgr,
																GroupLayout.PREFERRED_SIZE,
																21,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(lbl_Mgr)
														.addComponent(
																txt_Sal,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(lbl_Sal))
										.addGap(27)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.BASELINE)
														.addComponent(
																cancle_Btn)
														.addComponent(ok_Btn))
										.addGap(285)));
		contentPanel.setLayout(gl_contentPanel);
	}
}
